package com.javaxxf.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.javaxxf.service.ZiLiaoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author xuxiaofei
 * @date 2021年08月13日上午10:17
 */
@RestController
public class  ZiLiaoController {
     @Autowired
    private ZiLiaoService ziLiaoService;
     @RequestMapping("findAll")
     public void getAll(Integer currentPage, Integer pageSize, HttpServletResponse response) throws IOException {
        response.setContentType("text/html; charset=UTF-8");
         Page page = ziLiaoService.findAll(currentPage, pageSize);
         //封装PageInfo
         PageInfo info = new PageInfo(page);

         //将info转成json，响应给客户端
         String json = new ObjectMapper().writeValueAsString(info);
         System.out.println(json);
        response.getWriter().write(json);


     }


             }
